const mongo = require("../../model/api/Material ");
const { localTime } = require("../../utils/index");
const router = require("@koa/router")()

router.post("/add", async (ctx) => {
  const params = ctx.request.body;
  try {
    const res = await mongo.create({ ...params, time: localTime() })
    if (res && res.__v === 0) {
      ctx.body = {
        status: 0,
        message: "success",
        data: res
      }
    } else {
      ctx.body = {
        status: -1,
        message: "fail",
        data: null
      }
    }
  } catch (error) {
    console.log(error);
    ctx.body = {
      status: -1,
      message: error.message,
      data: null
    }
  }
})

module.exports = router